<template>
  <div class="AccManage">
    <h2>账号管理</h2>
    <div class="operatingBox">
      <div class="operating">
        <el-button type="success" icon="el-icon-plus" size="small" @click="addNotice">新增</el-button>
      </div>
      <div class="operating">
        <el-input placeholder="请输入姓名" v-model="searchContent" class="input-with-select">
          <el-button @click="mySearch" slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </div>
    </div>
    <div class="tab-content">
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%">

        <el-table-column prop="id" label="ID" width="55">
        </el-table-column>
        <el-table-column prop="type" label="类型" width="180">
          <template slot-scope="scope">
            <el-tag disable-transitions v-if="scope.row.type == 0">
              银联
            </el-tag>
            <el-tag disable-transitions v-if="scope.row.type == 1">
              微信
            </el-tag>
            <el-tag disable-transitions v-if="scope.row.type == 2">
              支付宝
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="head" label="标题" width="300">
        </el-table-column>
        <el-table-column prop="account" label="账号" width="300">
        </el-table-column>
        <el-table-column prop="name" label="开户人" width="180">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="300">
        </el-table-column>
        <el-table-column prop="status" label="状态" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag disable-transitions type="valid" v-if="scope.row.status == 0">
              有效
            </el-tag>
            <el-tag disable-transitions type="invalid" v-if="scope.row.status == 1">
              无效
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" prop="operation" label="操作" width="300">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit-outline" size="mini" @click="change(scope.row)">修改</el-button>
            <el-button type="danger" icon="el-icon-close" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination @getPagination="getPagination" :total="total" :pageSize="pageSize"></Pagination>
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
export default {
  name: '',
  components: {
    Pagination,
  },
  mixins: [],
  props: {

  },
  data() {
    return {
      pageSize: 5,
      currentPage:1,
      total: 0,
      searchContent: '',
      //表格数据
      tableData: [
        {
          "id": 1,
          "type": 0,//类型 0银联 1微信 2支付宝
          "head": "银联账户",//标题
          "account": "mojosada",//账号
          "name": "王五",//开户人
          "createTime": "2023-02-24 08:50:02",//创建时间
          "status": 0,//0有效1无效
          "description": null,
          "updateTime": null,
          "isDeleted": null
        }
      ],
    }
  },
  created() {
    this.$axios({//账号管理
      method: 'get',
      url: '/FinancialManagement/Account/findAccountList',
      params: {
        currentPage: 1,
        pageSize: 5
      }
    })
      .then(resp => {
        console.log(resp.data);
        this.total = parseInt(resp.data.data.total);
        this.tableData = resp.data.data.list;
      })
  },
  methods: {
    //新增
    addNotice() {
      this.$router.push('/financial/addAcc')
    },
    mySearch() {//条件查询
      if (this.searchContent == '') {
        this.$axios({//账号管理
          method: 'get',
          url: '/FinancialManagement/Account/findAccountList',
          params: {
            currentPage: 1,
            pageSize: 5
          }
        })
          .then(resp => {
            // console.log(resp.data);
            this.total = parseInt(resp.data.data.total);
            this.tableData = resp.data.data.list;
          })
      } else {
        this.$axios({//根据名字查询
          method: 'get',
          url: '/FinancialManagement/Account/findAccountByName',
          params: {
            name: this.searchContent,
            currentPage: 1,
            pageSize: 5,
          }
        })
          .then(resp => {
            // console.log(resp.data);
            this.total = parseInt(resp.data.data.total);
            this.tableData = resp.data.data.list;
          })
      }

    },
    handleDelete(index, row) {//删除
      console.log(index, row);
      this.$confirm('此操作将删除该财务管理信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 执行删除
        if (row.status == 1) {
          this.$axios.post(`/FinancialManagement/Account/deleteAccount?id=${row.id}`)
            .then(resp => {
              this.$axios({//删除成功后重新渲染页面
                method: 'get',
                url: '/FinancialManagement/Account/findAccountList',
                params: {
                  "currentPage": 1,//当前页数默认第一页
                  "pageSize": 5,//每页显示记录数
                }
              })
                .then(resp => {
                  this.total = parseInt(resp.data.data.total);
                  this.tableData = resp.data.data.list;
                  this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                })
            })
        } else {
          this.$message({
            message: '根据状态显示，该信息暂时无法删除',
            type: 'warning'
          });
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //获取点击的页码-------------------------------
    getPagination(page) {
      this.currentPage=page;
      this.$axios({
        method: 'get',
        url: '/FinancialManagement/Account/findAccountList',
        params: {
          "currentPage": this.currentPage,//当前页数默认第一页
          "pageSize": 5,//每页显示记录数
        }
      }).then(resp=>{
        this.total = parseInt(resp.data.data.total);
        this.tableData = resp.data.data.list;
      })
      
    },
    change(row){
      this.$router.push({
        path:'/Financial/editAcc',
        query:row
      })
    }
  },
  computed: {

  },
  watch: {

  },
  mounted() {

  },

};
</script>
<style lang='less' scoped>
h2 {
  margin: 15px;

}

.operatingBox {
  background-color: white;
  margin: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 3px solid #ccc;
  border-radius: 5px;
}

.operating {
  margin-top: 5px;
  margin-bottom: 5px;
  margin-left: 10px;
  margin-right: 10px;
}

.el-input {
  width: 200px;
}

.select {
  display: flex;
  flex-direction: column;
}

.labelText {
  text-align: left;
  float: left;
  font-size: 14px;
  font-weight: 600;
  color: black;
}

.el-form-item {
  display: flex;

  flex-direction: column;
}

.el-input {
  width: 250px;
}

.tab-content {
  margin: 10px;
}

.block {
  display: flex;
  justify-content: space-between;
  margin: 5px;
  padding: 5px 0px;
}
</style>